/*
 * Copyright (c) 2012-2013 XXXX XXXXXX, Inc.
 * XXXX Road, XXXX, XXXX State, XXXX Post code, XXXX Country.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of XXXX
 * XXXXXX, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with XXXX.
 * 
 * History
 * Date        Ver Author        Change Description
 * ----------- --- ------------- ----------------------------------------
 * 08 Jun 2013 002 Karl          Update xpath
 */
package test.com.sms.selenium.singlepoint.util;

import org.openqa.selenium.By;

import test.com.sms.selenium.framework.SeleniumPageUtil;
import test.com.sms.selenium.util.SeleniumUtil;

public class SpIncidentEditReasonsTabPageUtil extends SeleniumPageUtil {
	public final static By IER_LINK_SAVE = By.id("IncReasonsEdit1_btnSave");
	public final static By IER_LINK_DELETE = By.id("IncReasonsEdit1_btnDelete");
	public final static By IER_LINK_CLOSE = By.id("IncReasonsEdit1_btnDone");
	
	public final static By IER_TD_SERVICE_TYPE = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr[1]/td[1]");
	public final static By IER_SELECT_SERVICE_TYPE = By.id("IncReasonsEdit1_cboReasonGenID");
	public final static By IER_TD_GENERAL_REASON = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr[2]/td[1]");
	public final static By IER_SELECT_GENERAL_REASON = By.id("IncReasonsEdit1_cboReasonSpecID");
	public final static By IER_TD_SPECIFIC_REASON = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr[3]/td[1]");
	public final static By IER_SELECT_SPECIFIC_REASON = By.id("IncReasonsEdit1_cboReasonVerySpecID");
	public final static By IER_TD_NOTES = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr[4]/td[1]");
	public final static By IER_TEXTAREA_NOTES = By.id("IncReasonsEdit1_txtReasonNotes");
	
	public final static By IER_TD_SERVICE_TYPE2 = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr[1]/td[3]");
	public final static By IER_SELECT_SERVICE_TYPE2 = By.id("IncReasonsEdit1_cboResolutionGenID");
	public final static By IER_TD_GENERAL_RESOLUTION = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr[2]/td[3]");
	public final static By IER_SELECT_GENERAL_RESOLUTION = By.id("IncReasonsEdit1_cboResolutionSpecID");
	public final static By IER_TD_SPECIFIC_RESOLUTION = By.xpath("/html/body/form/div[3]/table/tbody/tr/td/table[4]/tbody/tr[3]/td[3]");
	public final static By IER_SELECT_SPECIFIC_RESOLUTION = By.id("IncReasonsEdit1_cboResolutionVerySpecID");
	public final static By IER_TD_NOTES2 = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr[4]/td[3]");
	public final static By IER_TEXTAREA_NOTES2 = By.id("IncReasonsEdit1_txtResolutionNotes");

	// new
	public final static By IER_LINK_NEW = By.id("IncReasonsList1_btnNew");
	public final static By IER_SPAN_NEW_TITLE = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[4]/tbody/tr/td[2]");
	// result table
	public final static By IER_TD_RESULT = By.id("IncReasonsList1_RRReport_ReportOutput");
	// first record of results
	public final static By IER_TR_RESULTS = By.xpath("//*[@id='IncReasonsList1_RRReport_ReportOutput']/table/tbody/tr");
	public final static By IER_TD_FIRST_RECORD = By.xpath("//*[@id='IncReasonsList1_RRReport_ReportOutput']/table/tbody/tr[3]/td");
	public final static By IER_TD_RE_GEN_REA = By.xpath("//*[@id='IncReasonsList1_RRReport_ReportOutput']/table/tbody/tr[2]/td[3]");
	public final static By IER_TD_RE_GEN_RES = By.xpath("//*[@id='IncReasonsList1_RRReport_ReportOutput']/table/tbody/tr[2]/td[4]");
	public final static By IER_TD_RE_GEN_NOTE = By.xpath("//*[@id='IncReasonsList1_RRReport_ReportOutput']/table/tbody/tr[2]/td[5]");
	public final static By IER_TD_RE_SPE_REA = By.xpath("//*[@id='IncReasonsList1_RRReport_ReportOutput']/table/tbody/tr[2]/td[7]");
	public final static By IER_TD_RE_SPE_RES = By.xpath("//*[@id='IncReasonsList1_RRReport_ReportOutput']/table/tbody/tr[2]/td[8]");
	public final static By IER_TD_RE_SPE_NOTE = By.xpath("//*[@id='IncReasonsList1_RRReport_ReportOutput']/table/tbody/tr[2]/td[9]");
	
	public static void enterReasonsTab(String incidentId){
		// login into homepage
		SpSearchPageUtil.enter();
		
		// make sure search button and incident id input text show
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_BUTTON_SEARCH)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_MAIN_INPUT_INCIDENT_ID)));

		// click the incident id link to enter the edit page
		SpIncidentEditPageUtil.enterIncidentID(incidentId);
		SeleniumUtil.click(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_LINK_TAB_REASONS));
		waitForPageToLoad();
	}
	public static void waitForPageToLoad(){
		SeleniumUtil.selectDefaultContent();
//		SeleniumUtil.waitOnElements(new By[]{
//				IER_LINK_SAVE,IER_SELECT_GEN_REA,IER_TD_RE_SPE_NOTE
//		});
	}
}
